const jwt = require('jsonwebtoken');
module.exports = () => {
    return async (ctx,next) => {
        let arr = ['/api/login','/api/registry'];
        if(arr.includes(ctx.request.path)){
            //没有token
            await next();
        }else{
            let token = ctx.request.header.token;
            console.log("token",ctx.get('token'));
            try{
                let info = jwt.verify(token,'1705b');
                ctx.info = info;
                await next();
            }catch(e){
                ctx.body = {
                    code:0,
                    msg:'token过期'
                }
            }
        }
    }
}